﻿using System;
using System.Linq;
using System.Linq.Expressions;
using ASPItalia.ModelVirtualCasting.Common;
using ASPItalia.ModelVirtualCasting.ObjectModel;
using System.Data;

namespace ASPItalia.ModelVirtualCasting.EntityFramework
{
	public class RequestRepository : BaseRepository<Request>, IRequestRepository
	{
		public RequestRepository(IContextContainer container) : base(container)
		{
		}
		
		public void InsertOnSubmit(Request entity)
		{
			CurrentObjectSet.AddObject(entity);
		}

		public void Update(Request entity)
		{
			CurrentObjectSet.Attach(entity);
			Context.ChangeObjectState(entity, EntityState.Modified);
		}

		public void DeleteOnSubmit(Request entity)
		{
			CurrentObjectSet.DeleteObject(entity);
		}
		
		public void SubmitChanges()
		{
			SaveChanges();
		}

		public IQueryable<Request> GetAll()
		{
			return CurrentObjectSet;
		}

		public IQueryable<Request> Where(Expression<Func<Request, bool>> predicate)
		{
			return CurrentObjectSet.Where(predicate);
		}

		public long Count(Expression<Func<Request, bool>> predicate)
		{
			return CurrentObjectSet.Count(predicate);
		}

		public IRequestRepository Include(string path)
		{
			CurrentObjectSet.Include(path);
			return this;
		}

		public IRequestRepository EnableLazyLoading()
		{
			SetLazyLoading(true);
			return this;
		}

		public IRequestRepository DisableLazyLoading()
		{
			SetLazyLoading(false);
			return this;
		}
	}
}